package com.ruoyi.pcj.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pcj.domain.PcjTbArticle;
import com.ruoyi.pcj.service.IPcjTbArticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 贴吧-文章Controller
 *
 * @author dk
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/pcj/article")
public class PcjTbArticleController extends BaseController
{
    @Autowired
    private IPcjTbArticleService pcjTbArticleService;

    /**
     * 分页查询贴吧-文章列表
     * @param params 最基本参数{"pageNum":1,"pageSize":10}，其他参数自行定义
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params)
    {
        IPage<PcjTbArticle> page = pcjTbArticleService.selectPcjTbArticleList(params);
        return getDataTableMp(page);
    }

    /**
     * 导出贴吧-文章列表
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:export')")
    @Log(title = "贴吧-文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params)
    {
        IPage<PcjTbArticle> page = pcjTbArticleService.selectPcjTbArticleList(params);
        ExcelUtil<PcjTbArticle> util = new ExcelUtil<PcjTbArticle>(PcjTbArticle.class);
        util.exportExcel(response, page.getRecords(), "贴吧-文章数据");
    }

    /**
     * 获取贴吧-文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(pcjTbArticleService.selectPcjTbArticleById(id));
    }


    /**
     * 新增贴吧-文章
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:add')")
    @Log(title = "贴吧-文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcjTbArticle pcjTbArticle)
    {
        return toAjax(pcjTbArticleService.insertPcjTbArticle(pcjTbArticle));
    }

    /**
     * 修改贴吧-文章
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:edit')")
    @Log(title = "贴吧-文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcjTbArticle pcjTbArticle)
    {
        return toAjax(pcjTbArticleService.updatePcjTbArticle(pcjTbArticle));
    }

    /**
     * 删除贴吧-文章
     */
    @PreAuthorize("@ss.hasPermi('pcj:article:remove')")
    @Log(title = "贴吧-文章", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(pcjTbArticleService.deletePcjTbArticleByIds(ids));
    }
}
